package cn.edu.whut.gateway.config;

import cn.edu.whut.gateway.config.properties.JwtConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;

import java.security.KeyPair;

@Configuration
@EnableConfigurationProperties(JwtConfigurationProperties.class)
public class SecurityConfig {

    @Bean
    public KeyPair keyPair(JwtConfigurationProperties jwtConfigurationProperties){
        // 获取秘钥工厂
        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
                jwtConfigurationProperties.getLocation(),
                jwtConfigurationProperties.getPassword().toCharArray());
        return keyStoreKeyFactory.getKeyPair(
                jwtConfigurationProperties.getAlias(),
                jwtConfigurationProperties.getPassword().toCharArray()
        );
    }
}
